import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useSystemStore = defineStore(
  'system',
  () => {
    const statusHeight = ref(0) // 状态栏高度 rpx

    const location = ref({}) // 位置信息

    const fontsize = ref('') // 字体大小
    const isNew = ref('')
    const casualUserInfo: any = ref({}) // 用户信息 临时存储

    const equipment: any = ref('') // 设备信息
    const launchFlag = ref(false)
    const isFirst = ref(1)
    const isNewStatus = ref()

    // 设置状态栏高度
    const setStatusHeight = (heightNum: any) => {
      try {
        statusHeight.value = heightNum * 2
      } catch (error) {}
    }

    // 设置设备信息
    const setEquipment = (equip: any) => {
      equipment.value = equip
    }

    // 设置位置信息
    const setLocation = (res: any) => {
      try {
        location.value = res
      } catch (error) {}
    }

    const setLaunchFlag = (i: any) => {
      launchFlag.value = i
    }
    // 设置字体大小
    const setFontsize = (size: any) => {
      fontsize.value = size
    }
    // 保存用户临时信息
    const setCasualUserInfo = (data: any) => {
      casualUserInfo.value = data
    }
    // 保存切换信息
    const setNewInfo = (data: any) => {
      isNewStatus.value = data
    }
    // 保存用户临时信息
    const setIsNew = (i: any) => {
      isNew.value = i
    }
    const setnum = (i: any) => {
      isFirst.value = i
    }
    return {
      statusHeight,
      setNewInfo,
      isNewStatus,
      location,
      setnum,
      isFirst,
      setLocation,
      setStatusHeight,
      fontsize,
      setIsNew,
      isNew,
      setFontsize,
      casualUserInfo,
      setCasualUserInfo,
      equipment,
      setEquipment,
      setLaunchFlag,
      launchFlag,
    }
  },
  {
    // 配置持久化
    persist: {
      storage: {
        getItem(key) {
          return uni.getStorageSync(key)
        },
        setItem(key, value) {
          uni.setStorageSync(key, value)
        },
      },
    },
  },
)
